﻿GoogleChrome:
;操作方面请使用Surfingkeys，只做功能补充
;定义注释
    vim.SetAction("<GoogleChrome_NormalMode>", "返回正常模式")
    vim.SetAction("<GoogleChrome_InsertMode>", "进入VIM模式")
    vim.SetWin("GoogleChrome", "","chrome.exe")

;normal模式（必需）
    vim.SetMode("normal", "GoogleChrome")
    vim.map("<insert>","<GoogleChrome_InsertMode>","GoogleChrome")
;vim.comment("<Phantom_切换到【VIM模式】>","按下Esc键可以切换为VIM模式")

;insert模式
    vim.SetMode("insert", "GoogleChrome")
    ;vim.Map("<esc>", "<GoogleChrome_NormalMode>", "GoogleChrome")
    vim.Map("x", "<GoogleChrome_关闭标签>", "GoogleChrome")
    vim.Map("X", "<GoogleChrome_全部关闭>", "GoogleChrome")
    vim.Map("d", "<GoogleChrome_下载>", "GoogleChrome")
    vim.Map("<Delete>", "<GoogleChrome_清除浏览数据>", "GoogleChrome")
    vim.Map("n", "<GoogleChrome_新建标签>", "GoogleChrome")
    vim.Map("<f8>", "<GoogleChrome_无痕>", "GoogleChrome")
    vim.Map("z", "<GoogleChrome_撤销>", "GoogleChrome")
    vim.map("1111","<ShowHelp>","GoogleChrome")
    vim.BeforeActionDo("GoogleChrome_BeforeActionDo", "GoogleChrome") 
return
; 对符合条件的控件使用insert模式，而不是normal模式
GoogleChrome_BeforeActionDo()
{
    ControlGetFocus, ctrl, AHK_CLASS Chrome_WidgetWin_1
	If RegExMatch(ctrl,"Chrome_RenderWidgetHostHWND1") ; || RegExMatch(ctrl,"i)qwidget")
        return true
    return false
}
;【全局运行AE】
<RunGoogleChrome>:
    GoogleChromePath := ini.BOBOPath_Config.GoogleChromePath
    GoogleChrome_Class := ini.ahk_class_Config.GoogleChrome_Class
    DetectHiddenWindows, on
    IfWinNotExist GoogleChromePath GoogleChrome_Class 
    { 
   		Run %GoogleChromePath%
    	WinActivate 
    } 
    	Else IfWinNotActive ahk_class GoogleChrome_Class 
    { 
    	WinActivate
    } 
    Else 
    { 
        WinMinimize 
    } 
 Return

GoogleChrome_CheckMode()
{
    ControlGetFocus, ctrl, AHK_CLASS GoogleChrome_Class
    ; msgbox, ctrl
    if RegExMatch(ctrl, "Edit2")
        return true
    return false
}

<GoogleChrome_关闭标签>:
{
    t := A_PriorHotkey == A_ThisHotkey && A_TimeSincePriorHotkey < 200 ? "off" : -200
    settimer, Google_tappedkey_x, %t%
    if (t == "off")
    goto Google_double_x
    return

    Google_tappedkey_x:
    Send {x}
    return

    Google_double_x:
    send, ^w
    return
}
return

<GoogleChrome_全部关闭>:
send, !{F4}
return

<GoogleChrome_下载>:
{
    t := A_PriorHotkey == A_ThisHotkey && A_TimeSincePriorHotkey < 200 ? "off" : -200
    settimer, Google_tappedkey_d, %t%
    if (t == "off")
    goto Google_double_d
    return

    Google_tappedkey_d:
    Send {d}
    return

    Google_double_d:
    send, ^j
    return
}

return

<GoogleChrome_清除浏览数据>:
    send ^+{Del}
return

<GoogleChrome_新建标签>:
{
    t := A_PriorHotkey == A_ThisHotkey && A_TimeSincePriorHotkey < 200 ? "off" : -200
    settimer, Google_tappedkey_n, %t%
    if (t == "off")
    goto Google_double_n
    return

    Google_tappedkey_n:
    Send {n}
    return

    Google_double_n:
    send, ^t
    return
}
return

<GoogleChrome_撤销>:
{
    t := A_PriorHotkey == A_ThisHotkey && A_TimeSincePriorHotkey < 200 ? "off" : -200
    settimer, Google_tappedkey_z, %t%
    if (t == "off")
    goto Google_double_z
    return

    Google_tappedkey_z:
    Send {z}
    return

    Google_double_z:
    send, ^z
    return
}
return

<GoogleChrome_无痕>:
    Send ^+{n}
return